
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
import java.util.Arrays;
import java.util.List;

public class compare {
    public static void main(String args[]){
        int n;
        String tmpName;
        int tmpAge;
        Scanner reader = new Scanner(System.in);
        n = reader.nextInt();
        PersonSortable people[] = new PersonSortable[n];
        for(int i=0; i<n; i++){
            tmpName = reader.next();
            tmpAge = reader.nextInt();
            people[i] = new PersonSortable(tmpName, tmpAge);
        }
        System.out.println("NameComparator:sort");
        List<PersonSortable> peopleS = Arrays.asList(people);
        Collections.sort(peopleS, new NameComparator());
        for(int i=0; i<n; i++){
            System.out.println(peopleS.toArray()[i]);
        }
        System.out.println("AgeComparator:sort");
        Collections.sort(peopleS, new AgeComparator());
        for (int i = 0; i < n; i++) {
            System.out.println(peopleS.toArray()[i]);
        }
        System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
        System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));
    }
}

class PersonSortable{
    private String name;
    private int age;
    PersonSortable(String n, int a){
        this.name = n;
        this.age = a;
    }

    String getName(){
        return name;
    }

    int getAge(){
        return age;
    }

    @Override
    public String toString(){
        return name + "-" + Integer.toString(age);
    }
}

class NameComparator implements Comparator<PersonSortable>{
    @Override
    public int compare(PersonSortable a, PersonSortable b){
        return a.getName().compareTo(b.getName());
    }
}

class AgeComparator implements Comparator<PersonSortable>{
    @Override
    public int compare(PersonSortable a, PersonSortable b){
        return a.getAge() < b.getAge() ? -1 : 1;
    }
}